package com.example.rss_reder;


import java.util.ArrayList;


import android.app.Service;
import android.content.Context;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainAdapter extends BaseAdapter{

	Context context;
	ArrayList<PlaceList> list;
	LayoutInflater inflater;
	int w1,w2;
	
	MainAdapter(Context c, ArrayList<PlaceList> l){
		this.context = c;
		this.list = l;
		inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		Display display = ((WindowManager)
				c.getSystemService(Service.WINDOW_SERVICE)).getDefaultDisplay();
			float windowWidth = display.getWidth();
			w1 = (int)(windowWidth/10*3);
			w2 = (int)(windowWidth/10*3.5);
	}


	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0).getPlace();
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		if(arg1 == null){
			arg1 = inflater.inflate(R.layout.list_main, arg2, false);
		}
		
		TextView tv1 = (TextView)arg1.findViewById(R.id.tv_dong);
		tv1.setWidth(w1);
		tv1.setText(list.get(arg0).getDong());

		TextView tv2 = (TextView)arg1.findViewById(R.id.tv_gu);
		tv2.setWidth(w1);
		tv2.setText(list.get(arg0).getGu());

		ArrayList<WeatherList> wlist = list.get(arg0).getList();
		WeatherList wl = wlist.get(0);
		
		TextView tv3 = (TextView)arg1.findViewById(R.id.tv_weather1);
		tv3.setWidth(w2);
		tv3.setText(wl.getWeather());
		
		TextView tv4 = (TextView)arg1.findViewById(R.id.tv_temp1);
		tv4.setWidth(w2);
		tv4.setText(wl.getMax()+"/"+wl.getMin());
		
		TextView tv5 = (TextView)arg1.findViewById(R.id.tv_rain1);
		tv5.setWidth(w2);
		tv5.setText(wl.getRain());
		
		WeatherList wl2 = wlist.get(7);
		
		TextView tv6 = (TextView)arg1.findViewById(R.id.tv_weather2);
		tv6.setWidth(w2);
		tv6.setText(wl2.getWeather());
		
		TextView tv7 = (TextView)arg1.findViewById(R.id.tv_temp2);
		tv7.setText(wl2.getMax()+"/"+wl2.getMin());
		tv7.setWidth(w2);
		
		TextView tv8 = (TextView)arg1.findViewById(R.id.tv_rain2);
		tv8.setWidth(w2);
		tv8.setText(wl2.getRain());

		return arg1;
	}

}
